import json


class Response:
    def __init__(self, code, msg, data):
        self.code = code
        self.msg = msg
        self.data = data

    @staticmethod
    def success(data):
        from app import app

        ret = Response(0, 'success', data)
        data = json.dumps(ret.__dict__, ensure_ascii=False)
        result = app.response_class(
            response=data,
            status=200,
            mimetype='application/json'
        )
        return result

    @staticmethod
    def success_page(data):
        from app import app

        ret = Response(0, 'success', data.get('records'))
        ret.page_num = data.get('page_num')
        ret.page_size = data.get('page_size')
        ret.total = data.get('total')
        data = json.dumps(ret.__dict__, ensure_ascii=False)
        result = app.response_class(
            response=data,
            status=200,
            mimetype='application/json'
        )
        return result
